import { http } from "@/utils/http"
import { postMemberCartData, MemeberCartItem, DeleteMemberCartData, PutMemeberCartByIdData } from '@/types/cart'
/**
 * 加入购物车
 * @param data
 * @returns
 */
export const postMemberCart = (data: postMemberCartData) =>
  http({
    url: '/member/cart',
    method: 'POST',
    data,
  })

/**
* 获取购物车列表
* @returns
*/
export const getMemeberCart = () =>
  http<MemeberCartItem[]>({ url: '/member/cart' })

/**
* 删除/清空购物车商品
* @param data
* @returns
*/
export const deleteMemberCart = (data: DeleteMemberCartData) =>
  http({
    url: '/member/cart',
    method: 'DELETE',
    data,
  })

/**
* 修改购物车商品
*/
export const putMemeberCartById = (id: string, data: PutMemeberCartByIdData) =>
  http({ url: `/member/cart/${id}`, method: 'PUT', data })

/**
* 购物车全选/取消全选
*/
export const putMemberCartSelected = (data: { selected: boolean, ids?: string[] }) =>
  http({ url: '/member/cart/selected', method: 'PUT', data })